package com.scarecrow.blit2d.impl {
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.IBitmapDrawable;
	import flash.geom.Point;
	
	/**
	 * This renderer displays a Flash displayObject onto the blitted scene, as a bitmap.
	 * 
	 * The display object used as source will not be kept in memory by this renderer.
	 * In the case of MovieClips this renderer will show only the frame being displayed
	 * by the movie at the moment of construction.
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class DefaultDisplayRenderer implements IDisplayRenderer {
		
		private var _drawPosition:Point;
		private var _displayData:BitmapData;
		private var _dirty:Boolean;
		private var _visible:Boolean;
		
		public function DefaultDisplayRenderer(displaySource:DisplayObject, smoothing:Boolean=false) {
			_displayData = new BitmapData(displaySource.width, displaySource.height, true, 0x00000000);
			_displayData.draw(displaySource, null, null, null, null, smoothing);
		}
		
		/* INTERFACE IDisplayRenderer */
		
		/**
		 * Returns an index for z-sorting.
		 */
		public function get zPos():Number {
			return _drawPosition.y + _displayData.height;
		}
		
		/**
		 * The position in which the renderer will be drawn.
		 */
		public function get drawPosition():Point {
			return _drawPosition;
		}
		
		/**
		 * The bitmapData being rendered.
		 */
		public function get displayData():BitmapData {
			return _displayData;
		}
		
		/**
		 * This value tells when to render this object.
		 * NOTE: currently not in use.
		 */
		public function get dirty():Boolean {
			return _dirty;
		}
		
		/**
		 * renderer visibility. works just as in a normal displayObject.
		 */
		public function get visible():Boolean {
			return _visible;
		}
		
	}

}